<%@ page import="com.factory.DAOFactory" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>删除学生信息</title>
    <script>
        // JavaScript 函数，用于确认删除操作
        function confirmDelete(studentId) {
            if (confirm("确定要删除该学生信息吗？")) {
                // 如果用户确认删除，跳转到 deleteStudents.jsp
                window.location.href = "deleteStudents.jsp?studentId=" + studentId;
            }
        }
    </script>
</head>
<body>
<%
    // 设置请求编码
    request.setCharacterEncoding("UTF-8");

    // 获取要删除的学生ID
    String studentId = request.getParameter("studentId");
    if (studentId == null || studentId.isEmpty()) {
        out.println("<script>alert('学生ID不能为空！'); window.location.href='showStudents.jsp';</script>");
    } else {
        boolean isSuccess = false;
        try {
            // 调用 DAO 删除学生信息
            isSuccess = DAOFactory.getStudentsDAOInstance().deleteStudents(studentId);
        } catch (Exception e) {
            e.printStackTrace();
        }

        // 根据删除结果跳转页面
        if (isSuccess) {
            out.println("<script>alert('学生信息删除成功！'); window.location.href='showStudents.jsp';</script>");
        } else {
            out.println("<script>alert('学生信息删除失败！'); window.location.href='showStudents.jsp';</script>");
        }
    }
%>
</body>
</html>